package com.zy.util;

import com.zy.model.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Set;

/**
 * 认证授权工具类
 */
public class AuthUtils {
    /**
     * 获取Security上下文中用户认证对象
     * @return
     */
    public static SecurityUser getLoginUser() {
        return  (SecurityUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 获取Security上下文中用户认证对象的userId
     * @return
     */
    public static Long getLoginUserId() {
        return getLoginUser().getUserId();
    }

    public static Set<String> getLoginUserPerms() {
        return getLoginUser().getPerms();
    }
}
